<template>
  <div class="app-container">
    <el-row v-if="!convertBuiness">
      <el-col :span="24">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
          label-width="68px">
          <el-form-item label="活动名称" prop="activityName">
            <el-input v-model="queryParams.activityName" placeholder="请输入活动名称" clearable
              @keyup.enter.native="handleQuery" />
          </el-form-item>
          <el-form-item label="主办单位" prop="sponsor">
            <el-input v-model="queryParams.sponsor" placeholder="请输入主办单位名称" clearable
              @keyup.enter.native="handleQuery" />
          </el-form-item>
          <el-form-item label="活动时间" prop="initiationTime">
            <el-date-picker clearable v-model="queryParams.initStartTime" type="datetime"
              value-format="yyyy-MM-dd HH:mm" placeholder="请选择开始时间">
            </el-date-picker>
            至
            <el-date-picker clearable v-model="queryParams.initEndTime" type="datetime" value-format="yyyy-MM-dd HH:mm"
              placeholder="请选择结束时间">
            </el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
          </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
        </el-row>
        <div style="width: 100%;height: 90vh;overflow:auto; margin-bottom: 30%;padding-bottom: 18%;position: relative;">
        <el-table :row-style="{ height: '30px' }" :cell-style="{ padding: '0px' }" height="450" border
          v-loading="loading" :data="trainingList" highlight-current-row>
          <el-table-column label="序号" type="index" :index="indexMethod" />
          <el-table-column label="状态" align="center" prop="status" v-if="columns[0].visible" />
          <el-table-column label="活动名称" align="center" prop="activityName" v-if="columns[1].visible"
            :show-overflow-tooltip="true" />
          <el-table-column label="主办单位" width="200" align="center" prop="sponsor" v-if="columns[3].visible"
            :show-overflow-tooltip="true" />
          <el-table-column label="类别" align="center" prop="type" v-if="columns[4].visible"
            :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.activity_type" :value="scope.row.type" />
            </template>
          </el-table-column>
          <el-table-column label="发起时间" align="center" prop="initiationTime" width="120" v-if="columns[5].visible"
            :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.initiationTime, '{y}-{m}-{d} ') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="形式" align="center" prop="lays" v-if="columns[5].visible" />
          <el-table-column label="开始时间" align="center" prop="startTime" width="130" v-if="columns[6].visible"
            :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <span>{{ parseUTCTime(scope.row.startTime, '{y}-{m}-{d} {hh}:{mm}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="结束时间" align="center" prop="endTime" width="130" v-if="columns[7].visible"
            :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <span>{{ parseUTCTime(scope.row.endTime, '{y}-{m}-{d} {hh}:{mm}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="地点" align="center" prop="location" v-if="columns[8].visible"
            :show-overflow-tooltip="true" />
          <el-table-column label="创建人" align="center" prop="creationName" v-if="columns[10].visible"
            :show-overflow-tooltip="true" width="100" />
          <el-table-column label="创建时间" align="center" prop="creationTime" width="120" v-if="columns[11].visible"
            :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.creationTime, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="联系人" align="center" prop="contacts" v-if="columns[12].visible"
            :show-overflow-tooltip="true" />
          <el-table-column label="联系电话" align="center" prop="telephone" v-if="columns[13].visible"
            :show-overflow-tooltip="true" />
          <el-table-column label="报名截止" align="center" prop="deadlineTime" width="120" v-if="columns[14].visible"
            :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <span>{{ parseUTCTime(scope.row.deadlineTime, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="参训人数" align="center" prop="partPersonNum" v-if="columns[16].visible"
            :show-overflow-tooltip="true" />
          <el-table-column label="参训企业数" width="100" align="center" prop="partEnterNum" v-if="columns[17].visible"
            :show-overflow-tooltip="true" />
          <el-table-column label="报名企业数量" width="100" align="center" prop="regiEnterprise" v-if="columns[18].visible"
            :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <!-- Assuming your prop name is regiEnterprise -->
              <a @click="handleClick(scope.row.activityId)" class="hyperlink">
                {{ scope.row.regiEnterprise }}
              </a>
            </template>
          </el-table-column>
          <el-table-column label="满意度平均分" width="100" align="center" prop="satisfactionScore"
            v-if="columns[19].visible" />
          <el-table-column label="费用" align="center" prop="fee" v-if="columns[20].visible" />
          <el-table-column label="发送方式" align="center" prop="sendType" v-if="columns[21].visible" >
            <template slot-scope="scope">
              <!-- Assuming your prop name is regiEnterprise -->
              <span >{{ scope.row.sendType === 'groupSend' ? '分类群发' : '一键发送' }}</span>
            </template>
          </el-table-column>
          <el-table-column label="活动报名人数" align="center" prop="peoplesNum" v-if="columns[22].visible" >
            <template slot-scope="scope">
              <!-- Assuming your prop name is regiEnterprise -->
              <span >{{ scope.row.peoplesNum}}</span>
            </template>
          </el-table-column>
          <el-table-column label="附件" align="center" prop="fileUpload">
            <template slot-scope="scope">
              <el-button @click="handlePictureCardPreview(scope.row.fileUpload)" size="small"
                v-if="scope.row.fileUrl != null && scope.row.fileUrl != ''" type="text">附件</el-button>
              <el-button size="small" v-else type="text">无附件</el-button>
            </template>
          </el-table-column>
          <el-table-column label="总结报告" align="center" prop="partUpload">
            <template slot-scope="scope">
              <el-button @click="handlePictureCardPreview(scope.row.partUpload)" size="small"
                         v-if="scope.row.partUrl != null && scope.row.partUrl != ''"
                type="text">附件</el-button>
              <el-button size="small" v-else type="text">无附件</el-button>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="170px" fixed="right">
            <template slot-scope="scope">
              <el-button :disabled="scope.row.status !== '审核' || scope.row.status === '终止' || scope.row.status === '结束'"
                size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row, scope.$index)" title="编辑"></el-button>
              <el-button size="mini" type="text" icon="el-icon-view"
                @click="handleSelect(scope.row, scope.$index)" title="查看"></el-button>
              <el-button :disabled="scope.row.status === '审核'" size="mini" type="text" icon="el-icon-s-opportunity"
                @click="convertBusiness(scope.row)" title="转为商机"></el-button>
              <el-button :disabled="!(scope.row.status !== '审核' && scope.row.examineStatus == 'through')" size="mini"
                type="text" icon="el-icon-magic-stick" @click="handleScore(scope.row, scope.$index)" title="评分"></el-button>
              <el-button :disabled="scope.row.status === '审核' || scope.row.status === '终止'"
                size="mini" type="text" icon="el-icon-download" @click="handleExport(scope.row)" title="导出"></el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize" @pagination="getList" />
        </div>
      </el-col>
    </el-row>
    <!-- 添加或修改活动信息培训对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body @close="closeTrain">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px" :inline="true">
        <div v-if="addSign !== 0">
          <el-descriptions title="">
            <el-descriptions-item label="序号">
              <el-tag size="medium">{{ form.index }}</el-tag>
            </el-descriptions-item>
          </el-descriptions>
        </div>
        <el-form-item label="活动名称" prop="activityName" label-width="110px">
          <el-input v-model="form.activityName" placeholder="请输入活动名称" :disabled="ReadOnly" style="width: 202.5px"
            maxlength="30" show-word-limit />
        </el-form-item>
        <el-form-item label="发起时间" prop="initiationTime" label-width="110px">
          <el-date-picker clearable v-model="form.initiationTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择发起时间" style="width: 202.5px" :disabled="ReadOnly">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="主办单位" prop="sponsor" label-width="110px">
          <el-input v-model="form.sponsor" type="textarea" placeholder="请输入主办单位"  :disabled="ReadOnly"
            style="width: 525px"  />
        </el-form-item>
        <el-form-item label="协办单位" prop="organizer" label-width="110px">
          <el-input v-model="form.organizer" type="textarea" placeholder="请输入协办单位"  :disabled="ReadOnly"
            style="width: 525px"  />
        </el-form-item>
        <el-form-item label="承办单位" prop="undertaker" label-width="110px">
          <el-input v-model="form.undertaker" type="textarea" placeholder="请输入承办单位"  :disabled="ReadOnly"
            style="width: 525px"  />
        </el-form-item>
        <el-form-item label="类别" prop="type" label-width="110px">
          <el-select v-model="form.type" placeholder="请选择形式" style="width: 100%;" :disabled="ReadOnly">
            <el-option v-for="dict in dict.type.activity_type" :key="dict.value" :label="dict.label"
              :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="形式" prop="lays" label-width="120px">
          <el-select v-model="form.lays" placeholder="请选择形式" style="width: 202.5px" :disabled="ReadOnly">
            <el-option label="线下" value="线下"></el-option>
            <el-option label="线上" value="线上"></el-option>
            <el-option label="线上+线下" value="线上+线下"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="开始时间" prop="startTime" label-width="110px">
          <el-date-picker v-model="form.startTime" type="datetime" placeholder="选择日期时间" value-format="yyyy-MM-dd HH:mm"
            :disabled="ReadOnly" style="width: 202.5px">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间" prop="endTime" label-width="110px">
          <el-date-picker v-model="form.endTime" type="datetime" placeholder="选择日期时间" value-format="yyyy-MM-dd HH:mm"
            :disabled="ReadOnly" style="width: 202.5px">
          </el-date-picker>

        </el-form-item>
        <el-form-item label="地点" prop="location" label-width="110px">
          <el-input v-model="form.location" placeholder="请输入地点" :disabled="ReadOnly" style="width: 202.5px"
            :title="ReadOnly ? form.location : ''" maxlength="30" show-word-limit />
        </el-form-item>
        <el-form-item label="联系人" prop="contacts" label-width="110px">
          <el-input v-model="form.contacts" placeholder="请输入联系人" :disabled="ReadOnly" style="width: 202.5px"
            maxlength="10" show-word-limit />
        </el-form-item>
        <el-form-item label="联系电话" prop="telephone" label-width="110px">
          <el-input v-model="form.telephone" placeholder="请输入联系电话" :disabled="ReadOnly" style="width: 202.5px"
            maxlength="11" show-word-limit />
        </el-form-item>
        <el-form-item label="报名截止" prop="deadlineTime" label-width="110px">
          <el-date-picker clearable v-model="form.deadlineTime" type="datetime" value-format="yyyy-MM-dd HH:mm"
            placeholder="请选择报名截止" style="width: 202.5px" :disabled="ReadOnly">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="费用" prop="fee" label-width="110px">
          <el-input v-model="form.fee" placeholder="请输入费用" :disabled="ReadOnly" style="width: 202.5px" />
        </el-form-item>
        <el-form-item label="区域" prop="region" label-width="110px">
          <Treeselect v-model="form.region" :options="optionsArea" style="width: 202.5px"
            :show-count="true" :normalizer="normalizer" placeholder="请选择区域" :disabled="ReadOnly" />
        </el-form-item>
        <el-form-item label="创建人" prop="creationName" label-width="110px">
          <el-input v-model="form.creationName" placeholder="请输入创建人" :disabled="true" style="width: 202.5px" />
        </el-form-item>
        <el-form-item label="创建时间" prop="creationTime" label-width="110px">
          <el-date-picker clearable v-model="form.creationTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择创建时间" style="width: 202.5px" :disabled="true">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="发送方式" prop="sendType" label-width="110px">
          <el-radio-group v-model="form.sendType" :disabled="ReadOnly">
            <el-radio label="oneClick">一键发送</el-radio>
            <el-radio label="groupSend">分类群发</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="form.sendType === 'groupSend'" label="群发内容" prop="receiverName" label-width="110px">
          <el-input v-model="form.receiverName" type="textarea" placeholder="请输入内容" style="width: 500px;" rows="5"
            @focus="handleTextAreaFocus" :disabled="ReadOnly" />
        </el-form-item>
        <el-form-item label="附件" prop="uploadFile" label-width="110px">
          <file-view v-if="show" :limit="uploadLimit" :type="typeSelect" :businessId="form.fileUpload"
            :businessCode="businessCode" style="width: 500px"></file-view>
        </el-form-item>
        <el-form-item label="审核状态" prop="examineStatus" label-width="110px"
          v-if="(addSign === 3 || addSign === 2) && form.sendType === 'oneClick'">
          <el-radio-group v-model="form.examineStatus" :disabled="ReadOnly">
            <el-radio label="through">审核通过</el-radio>
            <el-radio label="termination">审核不通过</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="终止原因" prop="endReason"
          v-if="form.examineStatus === 'termination' && (addSign === 3 || addSign === 2)" label-width="110px">
          <el-input v-model="form.endReason" type="textarea" placeholder="请输入终止原因" style="width: 535px" maxlength="300"
            show-word-limit :disabled="ReadOnly" />
        </el-form-item>
        <el-form-item label="参训人数" prop="partPersonNum" v-if="addSign === 3 && form.examineStatus == 'through'"
          label-width="110px">
          <el-input v-model="form.partPersonNum" placeholder="请输入参训人数" type="number" :min="0" style="width: 202.5px" />
        </el-form-item>
        <el-form-item label="参训企业数量" prop="partEnterNum" v-if="addSign === 3 && form.examineStatus == 'through'"
          label-width="110px">
          <el-input v-model="form.partEnterNum" placeholder="请输入参训企业数量" type="number" :min="0" style="width: 202.5px" />
        </el-form-item>
        <el-form-item label="满意度平均分" prop="satisfactionScore" v-if="addSign === 3 && form.examineStatus == 'through'"
          label-width="110px">
          <el-input v-model="form.satisfactionScore" placeholder="请输入满意度平均分" type="number" :min="0"
            style="width: 202.5px" />
        </el-form-item>
        <el-form-item label="总结报告" prop="partUpload" v-if="addSign === 3 && form.examineStatus == 'through'"
          label-width="110px">
          <file-view :limit="uploadLimit" v-if="show" :type="uploadType" :businessId="form.partUpload"
            :businessCode="businessCode" style="width: 130px"></file-view>
        </el-form-item>
        <el-form-item label="签到表" prop="signUpload" v-if="addSign === 3 && form.examineStatus == 'through'"
                      label-width="110px">
          <file-view :limit="1" v-if="show" :type="uploadType" :businessId="form.signUpload"
                     :businessCode="businessCode" style="width: 130px"></file-view>
        </el-form-item>
        <el-form-item label="活动照片" prop="activityPhoto" v-if="addSign === 3 && form.examineStatus == 'through'"
                      label-width="110px">
          <file-view :limit="1" v-if="show" :type="uploadType" :businessId="form.activityPhoto"
                     :businessCode="businessCode" style="width: 130px"></file-view>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" style="display: flex; justify-content: center;" v-if="addSign !== 2">
        <el-button type="primary" @click="submitForm" v-if="addSign !== 3">确 定</el-button>
        <el-button type="primary" @click="score" v-if="addSign === 3 && form.examineStatus == 'through'">评 分</el-button>
        <el-button @click="cancel">关 闭</el-button>
      </div>
      <div slot="footer" class="dialog-footer" style="display: flex; justify-content: center;" v-if="addSign === 2">
        <el-button @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>
    <el-dialog :title="title" :visible.sync="openUser" width="1000px" append-to-body>
      <!--      <el-scrollbar>-->

      <!--        <div class="content-box">-->
      <sendAll :markAs="1" @change="close" @ok="selectEnterprise" :enterprise="1" :isTree="false" :train="true" ref="sendAll">
      </sendAll>
      <!--        </div>-->
      <!--      </el-scrollbar>-->
    </el-dialog>
    <el-dialog title="报名情况" :visible.sync="Regi" width="1000px" append-to-body v-if="Regi">
      <enter :activityId="activityId"></enter>
    </el-dialog>
    <div v-if="convertBuiness">
      <Operate @change="closeEle" :opt="edit" :uuid="uuid" :isClick="isClick"></Operate>
    </div>
    <!--    <select-user ref="select" :type="userType" :sign="sign" @ok="selectUser" :isActOrQues=1></select-user>-->
    <SelectRoleUser ref="selectRole" :type="userType" :sign="sign" :menuId="menuId" @ok="selectUser">
    </SelectRoleUser>
    <!--    附件展示对话框-->
    <el-dialog title="查看附件" :visible.sync="openFileList" width="500px" append-to-body v-if="openFileList">
      <UploadFile :upload-id="uploadId" :business-code="businessCode"></UploadFile>
    </el-dialog>
    <!-- ********************************************************************************************************* -->
    <el-dialog title="供应商平台关系选择" :visible.sync="openSupplier" width="800px" append-to-body>
      <el-row>
        <el-col :span="24">
          <el-form :model="queryEnterpriseParams" ref="queryFormEnterprise" size="small" :inline="true"
            v-show="showSearch" label-width="100px">
            <el-form-item label="企业名称" prop="enterpriseName">
              <el-input v-model="queryEnterpriseParams.enterpriseName" placeholder="请输入企业名称" clearable
                @keyup.enter.native="handleQueryEnterprise" />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQueryEnterprise">搜索</el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="resetQueryEnterprise">重置</el-button>
              <el-button type="primary" size="mini" @click="saveSelectEnterprise">确定</el-button>
            </el-form-item>
          </el-form>
          <el-table ref="tableEnterprise" v-loading="loading" style="width: 100%"
            @selection-change="handleSelectionChangeEnterprise" :data="supplierList" row-key="enterpriseId">
            <el-table-column type="selection" width="45" align="center" :reserve-selection="true" />
            <el-table-column label="企业名称" align="center" prop="enterpriseName" />
            <el-table-column label="联系人" align="center" prop="contacts" />
            <el-table-column label="联系电话" align="center" prop="telephone" show-overflow-tooltip="true" />
          </el-table>
          <pagination v-show="total1 > 0" :total="total1" :page.sync="queryEnterpriseParams.pageNum"
            :limit.sync="queryEnterpriseParams.pageSize" @pagination="getEnterpriseList" />
        </el-col>
      </el-row>
    </el-dialog>
    <!-- *************************************************************************************************************************************** -->
  </div>
</template>

<script>
import { listTraining, getTraining, updateScore, addTraining, updateTraining } from "@/api/activity/training";
import { listInfoType, listInfo, listInfoToActivity } from "@/api/supplier/supplier";
import { listType } from "@/api/maintype/type";
import MainType from "@/components/MainType/index"
import FileView from "@/components/FileView/index"
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import BusinessInfo from "../../enterprise/info/index.vue";
import SelectUser from "../../system/role/selectUser.vue";
import Operate from "../../enterprise/businessinfo/operate.vue";
import Enter from "./enter.vue";
import UploadFile from "../../upload/index.vue";
import SelectRoleUser from "../../system/role/selectUser.vue";
import sendAll from "../../enterprise/info/sendAll.vue";
import { listArea } from "@/api/area/area";
export default {
  name: "Training",
  components: {
    SelectRoleUser, UploadFile, Operate, SelectUser, BusinessInfo, Treeselect, MainType, FileView, Enter, sendAll
  },
  dicts: ['activity_type'],
  data() {
    var enterpriseName = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('主办单位不能为空'));
      }
      return callback()
    };
    return {
      uploadLimit: 1,
      showType: 0,
      openSupplier: false,
      activeNewName: 'one',
      orgId: null,
      uuid: "",
      edit: 'add',
      menuId: '2079',
      isClick: true,
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      total1: 0,
      total2: 0,
      typeCode: 'train',
      // 活动信息培训表格数据
      trainingList: [],
      infoList: [],
      supplierList: [],
      ids: [],
      eIds: [],
      sIds: [],
      eName: [],
      sName: [],
      uploadId: null,
      openFileList: false,
      // 弹出层标题
      title: "",
      //详情状态
      ReadOnly: false,
      //行政区域
      optionsArea: null,
      // 是否显示弹出层
      open: false,
      //判断对话框是否新增或编辑
      addSign: 0,
      //图片的标志位
      show: false,
      dialogImageUrl: null,
      ImgDig: false,
      uploadType: 1,
      typeSelect: 0,
      businessCode: 'train',
      //主分类
      options: null,
      userType: "1",
      sign: '2',
      pickerOptions: {
        disabledDate: (time) => {
          // 禁用今天之前的日期选择
          return time.getTime() < new Date().getTime() - 24 * 60 * 60 * 1000;
        },
      },
      queryEnterpriseParams: {
        pageNum: 1,
        pageSize: 5,
        enterpriseName: null,
        enterpriseOrgId: null,
        industry: null,
        industryType: null,
        belongTo: null,
      },
      querySeasParams: {
        pageNum: 1,
        pageSize: 5,
        enterpriseName: null,
        enterpriseOrgId: null,
        industry: null,
        industryType: null,
        belongTo: null,
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 15,
        activityName: null,
        activityId:null,
        initStartTime: null,
        initEndTime: null,
        classificationId: null,
        initiationUnit: null
      },
      activityId: null,
      convertBuiness: false,
      openUser: false,
      // 列信息
      columns: [
        { key: 0, label: `状态`, prop: "status", visible: true },
        { key: 1, label: `活动名称`, prop: "activityName", visible: true },
        { key: 2, label: `发起单位`, prop: "initiationUnit", visible: true },
        { key: 3, label: `主办单位`, prop: "sponsor", visible: true },
        { key: 4, label: `类别`, prop: "type", visible: true },
        { key: 5, label: `形式`, prop: "lays", visible: true },
        { key: 6, label: `发起时间`, prop: "initiationTime", visible: true },
        { key: 7, label: `开始时间`, prop: "startTime", visible: true },
        { key: 8, label: `结束时间`, prop: "endTime", visible: true },
        { key: 9, label: `地点`, prop: "location", visible: true },
        { key: 10, label: `创建人`, prop: "creationName", visible: true },
        { key: 11, label: `创建时间`, prop: "creationTime", visible: true, },
        { key: 12, label: `联系人`, prop: "contacts", visible: true },
        { key: 13, label: `联系电话`, prop: "telephone", visible: true },
        { key: 14, label: `报名截止`, prop: "deadlineTime", visible: true },
        { key: 15, label: `审核人`, prop: "examineName", visible: true },
        { key: 16, label: `参训人数`, prop: "partPersonNum", visible: true },
        { key: 17, label: `参训企业数量`, prop: "partEnterNum", visible: true },
        { key: 18, label: "报名企业数", prop: "regiEnterprise", visible: true },
        { key: 19, label: `满意度平均分`, prop: "satisfactionScore", visible: true },
        { key: 20, label: `费用`, prop: "fee", visible: true },
        {key: 21, label: `发送方式`, prop: "sendType", visible: true },
        {key: 22, label: `活动报名人数`, prop: "peoplesNum", visible: true }
      ],
      Regi: false,
      // 表单参数
      form: {},
      activityName: [{ required: true, message: '请输入活动名称', trigger: 'blur' }],
      rules: {
        deadlineTime: [
          { required: true, message: '请选择报名截止时间', trigger: 'blur' },
          {
            validator: (rule, value, callback) => {
              const startTime = this.form.startTime;
              const endTime = this.form.endTime;
              if (value && (value > startTime || value > endTime)) {
                callback(new Error('报名截止时间不能大于开始时间和结束时间'));
              } else {
                callback();
              }
            },
            trigger: 'blur',
          },
        ],
        startTime: [
          { required: true, message: '请选择开始时间', trigger: 'blur' },
          {
            validator: (rule, value, callback) => {
              const deadlineTime = this.form.deadlineTime;
              const endTime = this.form.endTime;
              if (value && value > endTime) {
                callback(new Error('开始时间不能大于结束时间'));
              } else if (value && value < deadlineTime) {
                callback(new Error('开始时间不能小于报名截止时间'));
              } else {
                callback();
              }
            },
            trigger: 'blur',
          },
        ],
        endTime: [
          { required: true, message: '请选择结束时间', trigger: 'blur' },
          {
            validator: (rule, value, callback) => {
              const startTime = this.form.startTime;
              if (value && value < startTime) {
                callback(new Error('结束时间不能小于开始时间'));
              } else {
                callback();
              }
            },
            trigger: 'blur',
          },
        ],
        creationName: [{ required: true, message: '请输入创建人', trigger: 'blur' }],
        activityName:[{required: true, message: '请输入活动名称', trigger: 'blur'}],
        creationTime: [{ required: true, message: '请选择创建时间', trigger: 'blur' }],
        initiationUnit: [{ required: true, message: '请输入发起单位', trigger: 'blur' }],
        sponsor: [{required: true, message: '请输入主办单位', trigger: 'blur' }],
        initiationTime: [{ required: true, message: '请选择发起时间', trigger: 'blur' }],
        type: [{ required: true, message: '请输入类别', trigger: 'blur' }],
        lays: [{ required: true, message: '请选择形式', trigger: 'blur' }],
        location: [{ required: true, message: '请输入地点', trigger: 'blur' }],
        contacts: [{ required: true, message: '请输入联系人', trigger: 'blur' }],
        telephone: [{ required: true, message: '请输入联系电话', trigger: 'blur' }],
        examineName: [{ required: true, message: '请输入审核人', trigger: 'change' }],
        fee: [
          { required: true, message: '请输入费用', trigger: 'blur' },
          { validator: this.validateNumber, trigger: 'blur' },
        ],
        sendType: [{ required: true, message: '请选择发送方式', trigger: 'blur' }],
        receiverName: [{ required: true, message: '请输入群发内容', trigger: 'change' }],
        partPersonNum: [
          { required: true, message: '请输入参训人数', trigger: 'blur' },
          { validator: this.validateNumber, trigger: 'blur' },
        ],
        partEnterNum: [
          { required: true, message: '请输入参训企业数量', trigger: 'blur' },
          { validator: this.validateNumber, trigger: 'blur' },
        ],
        satisfactionScore: [
          { required: true, message: '请输入满意度平均分', trigger: 'blur' },
          { validator: this.validateNumber, trigger: 'blur' },
        ],
      },
    };
  },
  created() {
    this.orgId = this.$store.state.user.info.orgId;
    this.getList();
    this.listType();
    this.area();
    this.getEnterpriseList();
  },
  methods: {
    supplierCheck(ids) {
      this.supplierList.forEach(item => {
        for (var j = 0; j < ids.length; j++) {
          if (item.enterpriseId == ids[j]) {
            this.$refs.tableEnterprise.toggleRowSelection(item, true);
          }
        }
      })
    },
    saveSelectEnterprise() {
      if (this.eIds.toString() == "" || this.eIds.toString() == null) {
        this.$modal.msgError("请先选择供应商！");
      } else {
        if (this.showType == '1') {
          this.$set(this.form, 'sponsor', this.eName.toString())
          this.$set(this.form, 'sponsorId', this.eIds.toString())
        } else if (this.showType == '2') {
          this.$set(this.form, 'organizer', this.eName.toString())
          this.$set(this.form, 'organizerId', this.eIds.toString())
        } else if (this.showType == '3') {
          this.$set(this.form, 'undertaker', this.eName.toString())
          this.$set(this.form, 'undertakerId', this.eIds.toString())
        }
        this.closeSupplier()
      }
    },
    handleNewClick(tab, event) {
      if (tab.name == 'one') {
        this.$refs.tableSeas.clearSelection(); // 清空所有选择
      }
      if (tab.name == 'two') {
        this.$refs.tableEnterprise.clearSelection(); // 清空所有选择
      }
    },
    saveSelectSeas() {
      if (this.sIds.toString() == "" || this.sIds.toString() == null) {
        this.$modal.msgError("请先选择平台关系！");
      } else {
        if (this.showType == '1') {
          this.$set(this.form, 'sponsor', this.sName.toString())
          this.$set(this.form, 'sponsorId', this.sIds.toString())
        } else if (this.showType == '2') {
          this.$set(this.form, 'organizer', this.sName.toString())
          this.$set(this.form, 'organizerId', this.sIds.toString())
        } else if (this.showType == '3') {
          this.$set(this.form, 'undertaker', this.sName.toString())
          this.$set(this.form, 'undertakerId', this.sIds.toString())
        }
        this.closeSupplier()
      }
    },
    handleSelectionChangeSeas(selection) {
      this.sIds = selection.map(item => item.enterpriseId)
      this.sName = selection.map(item => item.enterpriseName)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    handleSelectionChangeEnterprise(selection) {
      this.ids = selection.map(item => item.enterpriseId)
      this.eIds = selection.map(item => item.enterpriseOrgId)
      this.eName = selection.map(item => item.enterpriseName)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    enterprise(type) {
      var arrs = [];
      this.resetQueryEnterprise();
      this.showType = type;
      this.activeNewName = "one";
      var ids = "";
      if (type == 1) {
        ids = this.form.sponsorId;
      } else if (type == 2) {
        ids = this.form.organizerId;
      } else {
        ids = this.form.undertakerId;
      }
      setTimeout(() => {
        this.openSupplier = true;
      }, 300);
      if (ids != null && ids != '' && ids != "undefined") {
        if (ids.indexOf(",") != -1) {
          arrs = ids.split(",");
        } else {
          arrs.push(ids);
        }
        setTimeout(() => {
          this.supplierCheck(arrs);
        }, 500);
      } else {
        this.$refs.tableEnterprise.clearSelection();
      }
    },
    getEnterpriseList() {
      this.loading = true;
      this.queryEnterpriseParams.belongTo = this.$store.state.user.info.orgId;
      listInfoToActivity(this.queryEnterpriseParams).then(response => {
        this.supplierList = response.rows;
        this.total1 = response.total;
        this.loading = false;
      });
    },
    getSeasList() {
      this.loading = true;
      this.querySeasParams.belongTo = this.$store.state.user.info.orgId;
      this.querySeasParams.enterpriseOrgId = this.$store.state.user.info.orgId;
      listInfoType(this.querySeasParams).then(response => {
        this.infoList = response.rows;
        this.total2 = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQueryEnterprise() {
      var arrs = [];
      this.queryEnterpriseParams.pageNum = 1;
      this.getEnterpriseList();
      var type = this.showType;
      this.activeNewName = "one";
      var ids = "";
      if (type == 1) {
        ids = this.form.sponsorId;
      } else if (type == 2) {
        ids = this.form.organizerId;
      } else {
        ids = this.form.undertakerId;
      }
      setTimeout(() => {
        this.openSupplier = true;
      }, 300);
      if (ids != null && ids != '' && ids != "undefined") {
        if (ids.indexOf(",") != -1) {
          arrs = ids.split(",");
        } else {
          arrs.push(ids);
        }
        setTimeout(() => {
          this.supplierCheck(arrs);
        }, 500);
      }
    },
    /** 重置按钮操作 */
    resetQueryEnterprise() {
      this.resetForm("queryFormEnterprise");
      this.handleQueryEnterprise();
    },
    /** 搜索按钮操作 */
    handleQuerySeas() {
      this.querySeasParams.pageNum = 1;
      this.getSeasList();
    },
    /** 重置按钮操作 */
    resetQuerySeas() {
      this.resetForm("queryFormSeas");
      this.handleQuerySeas();
    },
    //费用校验
    validateNumber(rule, value, callback) {
      if (value === '' || /^[0-9]+(\.[0-9]+)?$/.test(value)) {
        callback();
      } else {
        callback(new Error('请输入合法的数字'));
      }
    },
    /** 导出按钮操作 */
    handleExport(row) {
     if (row. regiEnterprise>0){
       this.download('/activity/training/export/regi', {
         activityId:row.activityId
       }, `企业报名人员信息表.xlsx`)
     }
    },
    /** 查询活动信息培训列表 */
    getList() {
      this.loading = true;
      listTraining(this.queryParams).then(response => {
        this.trainingList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    area() {
      listArea({}).then(response => {
        this.optionsArea = response.data;
      });
    },
    parseUTCTime(time, format) {
      const date = new Date(time.replace('T', ' ').replace('+08', ''));
      const year = date.getFullYear();
      const month = String(date.getMonth() + 1).padStart(2, '0');
      const day = String(date.getDate()).padStart(2, '0');
      const hours = String(date.getHours()).padStart(2, '0');
      const minutes = String(date.getMinutes()).padStart(2, '0');
      return format.replace('{y}', year).replace('{m}', month).replace('{d}', day).replace('{hh}', hours).replace('{mm}', minutes);
    },
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.areaId,
        label: node.areaName,
        isDisabled: false,
        children: node.list && node.list.length > 0 ? node.list : 0
      }
    },
    //获取树节点数据
    listType() {
      listType({ typeCode: 'train' }).then(res => {
        console.log(res);
        this.options = res.data;
      })
    },
    selectUser(userId, userName) {
      this.$set(this.form, 'examineId', userId)
      this.$set(this.form, 'examineName', userName)
    },

    // //报名截止日期控件
    // dateOptions(time) {
    //   return time.getTime() < Date.now() - 24 * 60 * 60 * 1000
    //:picker-options="{ disabledDate: dateOptions }"
    // },
    //关闭对话框
    closeTrain() {
      this.ReadOnly = false;
      this.show = false;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.show = false;
      this.addSign = 0;
      this.reset();
    },
    //转商机
    convertBusiness(row) {
      if (this.$store.state.user.info.companyType==='2'){
        this.$router.push({ path: "/activityinfo/demand", query: { isTrue: true } });
      }else {
        this.uuid = this.guid();
        this.edit = "add";
        this.isClick = true;
        this.convertBuiness = true;
      }
    },
    closeEle() {
      this.convertBuiness = false;
    },
    //点击接收方文本域,弹出选择当前用户在企业管理中的企业信息
    handleTextAreaFocus() {
      this.openUser = true;
    },
    selectOpen(type) {
      this.userType = 1;
      this.$refs.selectRole.show();
    },
    //获取当前用户在企业管理中的企业信息
    selectEnterprise(selection) {
      this.form.enterpriseId = selection.map(item => item.enterpriseId);
      this.form.receiverName = selection.map(item => item.enterpriseName).join('\n'); // 修改这里
      console.log(this.form)
      this.close()
    },
    guid() {
      function S4() {
        return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
      }
      return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
    },
    close() {
      this.openUser = false
    },
    closeSupplier() {
      this.openSupplier = false
    },
    // 表单重置
    reset() {
      this.form = {
        activityId: null,
        activityName: null,
        initiationUnit: null,
        sponsorId: null,
        sponsor: null,
        undertakerId: null,
        undertaker: null,
        organizerId: null,
        organizer: null,
        type: null,
        initiationTime: null,
        lays: null,
        startTime: null,
        endTime: null,
        location: null,
        receiverId: null,
        receiverName: null,
        operateTime: null,
        status: null,
        operateId: null,
        operateName: null,
        departmentId: null,
        departmentName: null,
        organizationId: null,
        organizationName: null,
        createId: null,
        creationName: null,
        creationTime: null,
        belongTo: null,
        classificationId: null,
        contacts: null,
        telephone: null,
        deadlineTime: null,
        examineId: null,
        examineName: null,
        fileUpload: null,
        partPersonNum: null,
        partEnterNum: null,
        satisfactionScore: null,
        //客户id数组
        enterpriseId: [],
        sendType: null,
        partUpload: null,
        activityPicture: null,
        region: null,
        version:null,
        peoplesNum:null,
        signUpload:null,
        activityPhoto:null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      if (this.queryParams.initStartTime > this.queryParams.initEndTime) {
        this.$message.error("请重新添加日期查询条件");
      } else {
        this.getList();
      }
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.initStartTime = null;
      this.queryParams.initEndTime = null;
      this.resetForm("queryForm");
      this.handleQuery();
    },
    //树点击事件
    getNode(data, node, obj) {
      console.log(data)
      if (data.parentId != '00000000-0000-0000-0000-000000000000') {
        this.queryParams.classificationId = data.id
      } else {
        this.queryParams.classificationId = null
      }
      this.getList()
    },
    //当有值的时候，默认打开对话框为分类群发，没值为一键发送
    sendTrain() {
      if (this.form.receiverName !== null) {
        this.sendType = "groupSend"
      } else {
        this.sendType = "oneClick"
      }
    },
    //序号展示
    indexMethod(index) {
      return (this.queryParams.pageNum - 1) * this.queryParams.pageSize + index + 1;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.listType();
      this.sendTrain();
      this.form.fileUpload = String(new Date().getTime());
      this.form.creationTime = new Date();
      this.form.activityPicture = String(new Date().getTime() + 20);
      this.form.partUpload = String(new Date().getTime() + 40);
      this.form.signUpload = String(new Date().getTime() + 60);
      this.form.activityPhoto = String(new Date().getTime() + 80);
      this.form.creationName = this.$store.state.user.name;
      if (this.queryParams.classificationId === null) {
        this.form.classificationId = '650c44e1-b575-4b62-9d54-1ba9d1e8abb7'
      } else {
        this.form.classificationId = this.queryParams.classificationId;
      }
      this.addSign = 0;
      this.typeSelect = 0;
      this.title = "添加活动信息培训";
      this.open = true;
      this.show = true;
    },
    /** 修改按钮操作 */
    handleUpdate(row, index) {
      this.reset();
      this.listType();
      const activityId = row.activityId || this.ids
      getTraining(activityId).then(response => {
        this.form = response.data;
        if (this.form.activityPhoto === null) {
          this.form.activityPhoto = new Date().getTime()+40;
        }
        if (this.form.signUpload === null) {
          this.form.signUpload = new Date().getTime()+80;
        }
        this.sendTrain();
        this.open = true;
        this.typeSelect = 1;
        this.show = true;
        this.addSign = 1;
        this.form.index = index + 1;
        //把接收方的id转成数组
        this.form.enterpriseId = this.form.receiverId.split(',');
        this.title = "修改活动信息培训";
      });
    },
    /** 查看按钮操作 */
    handleSelect(row, index) {
      this.reset();
      const activityId = row.activityId || this.ids
      getTraining(activityId).then(response => {
        this.form = response.data;
        this.ReadOnly = true;
        this.open = true;
        this.typeSelect = 2;
        this.form.index = index + 1;
        this.addSign = 2;
        this.show = true;
        this.title = "查看活动信息培训";
      });
    },
    //评分
    handleScore(row, index) {
      const activityId = row.activityId || this.ids
      getTraining(activityId).then(response => {
        this.form = response.data;
        this.ReadOnly = true;
        this.open = true;
        this.typeSelect = 2;
        this.form.index = index + 1;
        this.addSign = 3;
        this.show = true;
        //把接收方的id转成数组
        this.form.enterpriseId = this.form.receiverId.split(',');
        this.title = "活动信息培训评分";
      });
    },
    handleClick(activityId) {
      this.Regi = true;
      this.activityId = activityId;
    },
    //评分
    score() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          updateScore(this.form).then(res => {
            this.$modal.msgSuccess("评分成功");
            this.open = false;
            this.show = false;
            this.getList();
          })
        }
      });
    },
    handlePictureCardPreview(id) {
      this.uploadId = id;
      this.openFileList = true;
    },
    //让分类群发关闭多选框
    provideEnter(){

    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.activityId != null) {
            updateTraining(this.form).then(response => {
              if (response.code === 200) {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
                this.$refs.sendAll.clearTable();
              } else {
                this.$message.error(response.msg);
                this.open = false;
                this.getList();
              }
            });
          } else {
            addTraining(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.show = false;
              this.getList();
              this.$refs.sendAll.clearTable();
            });
          }
        }
      });
    },
  }
};
</script>
<style scoped>
.hyperlink {
  color: #007BFF;
  /* 蓝色 */
  text-decoration: underline;
  cursor: pointer;
}
</style>
